package cd.cdyb.sms.controller;


import cd.cdyb.sms.dto.PageResult;
import cd.cdyb.sms.dto.SmsExcessDto;
import cd.cdyb.sms.dto.expand.ExCompanyDto;
import cd.cdyb.sms.dto.query.CompanyQueryDto;
import cd.cdyb.sms.exception.BusinessException;
import cd.cdyb.sms.service.CompanyService;
import cd.cdyb.sms.utils.UserUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lin
 * @since 2024-05-14
 */
@RestController
@RequestMapping("/company")
public class CompanyController {


    @Resource
    private CompanyService companyService;

    /**
     * 新增
     */
    @PostMapping("/insertCompany")
    public void insertCompany(@RequestBody @Valid ExCompanyDto exCompanyDto) throws BusinessException {
        companyService.insertCompany(exCompanyDto);
    }

    /**
     * 编辑
     */
    @PostMapping("/updateCompany")
    public void updateCompany(@RequestBody @Valid ExCompanyDto exCompanyDto) throws BusinessException {
        companyService.updateCompany(exCompanyDto);
    }

    /**
     * 查询用户分页
     *
     * @param companyQueryDto 查询条件
     * @return 查询结果
     */
    @PostMapping("/findCompanyPage")
    public PageResult<ExCompanyDto> findCompanyPage(@RequestBody  CompanyQueryDto companyQueryDto) throws BusinessException {
        return companyService.findCompanyPage(companyQueryDto);
    }

    @PostMapping("/getCompanyById")
    public ExCompanyDto getCompanyById(@RequestBody ExCompanyDto exCompanyDto) throws BusinessException {
        return companyService.getCompanyById(exCompanyDto.getCompanyId());
    }

    /**
     * 客服端-短信余量
     */
    @PostMapping("/getSmsExcessWithClient")
    public SmsExcessDto getSmsExcessWithClient() throws BusinessException {
        return companyService.getSmsExcessWithClient(UserUtils.getCompanyId());
    }


    /**
     * 管理端-短信余量
     */
    @PostMapping("/getSmsExcessWithAdmin")
    public List<SmsExcessDto> getSmsExcessWithAdmin() {
        return companyService.getSmsExcessWithAdmin();
    }

    /**
     * 公司列表
     */
    @PostMapping("/findCompanyList")
    public List<ExCompanyDto> findCompanyList() {
        return companyService.findCompanyList();
    }

}

